import request from '@/utils/request'
enum API {
  ALLROLELIST_URL = '/admin/acl/role/',
  ADDROLEINFO_URL = '/admin/acl/role/save',
  UPDATEROLE_URL = '/admin/acl/role/update',
  ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
  ASSGINPERMISSON_URL = '/admin/acl/permission/doAssign/',
  DELETEROLE_URL = '/admin/acl/role/remove/'
}
export const reqRoleList = (page: number, limit: number, roleName: string) => {
  return request.get<any, any>(API.ALLROLELIST_URL + `${page}/${limit}/?roleName=${roleName}`)
}
export const reqAddOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEROLE_URL, data)
  }
  return request.post<any, any>(API.ADDROLEINFO_URL, data)
}
export const reqAllPermissionList = (roleId: string) => {
  return request.get<any, any>(API.ALLPERMISSION_URL + `${roleId}`)
}
export const reqAssignPermission = (roleId: string, permissionId: string[]) => {
  return request.post<any, any>(
    API.ASSGINPERMISSON_URL + `?roleId=${roleId}&permissionId=${permissionId}`
  )
}
export const reqDeleteRole = (id: string) => {
  return request.delete<any, any>(API.DELETEROLE_URL + `${id}`)
}
